local jiezhu = fk.CreateSkill({
    name = "sj7__jiezhu",
})

Fk:loadTranslationTable{
  ["sj7__jiezhu"] = "借诛",
  [":sj7__jiezhu"] = "出牌阶段开始时，你可以令任意名角色各交给你一张手牌，然后你展示这些牌:若均为黑色，则视为无次数限制的【杀】，否则这些角色依次将交出的黑色牌当【杀】对你使用。",
  

  ["#sj7__jiezhu"] = "借诛：你可以令任意名角色各交给你一张手牌",
  ["#sj7__jiezhu-give"] = "借诛：交给 %dest 一张手牌",

  ["@@sj7__jiezhu"] = "借诛",

  ["$sj7__jiezhu1"] = "检阅士卒，备将行之役。",
  ["$sj7__jiezhu2"] = "点选将校，讨乱汉之贼。",
}

jiezhu:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target ,player, data)
      return player:hasSkill(jiezhu.name) and target == player and player.phase == Player.Play
    end,
    on_cost = function (self, event, target, player, data)
      local room = player.room
      local ts = table.filter(room:getOtherPlayers(player),function (t)
        return not t:isKongcheng()
      end)
      if #ts == 0 then return end
      local ps = room:askToChoosePlayers(player,{
        targets = ts,
        min_num = 1,
        max_num = 999,
        skill_name = jiezhu.name,
        prompt = "#sj7__jiezhu",
      })
      if #ps > 0 then
        event:setCostData(self,{ps = ps})
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local ps = event:getCostData(self).ps
      local tc = room:askToJointCards(player,{
        players = ps,
        min_num = 1,
        max_num = 1,
        skill_name = jiezhu.name,
        prompt = "#sj7__jiezhu-give::"..player.id,
        cancelable = false,
      })
      for _, p in ipairs(room:getOtherPlayers(player)) do
        for t, c in pairs(tc) do
          if p.id == t.id and table.contains(p:getCardIds("h"),c[1]) and not player.dead then
            room:obtainCard(player,c,false,fk.ReasonGive,p,jiezhu.name)
          end
        end
      end
      local cards = table.filter(player:getCardIds("h"),function (id)
        for _, c in pairs(tc) do
          if table.contains(c,id) then
            return true
          end
        end
      end)
      if #cards == 0 then return end
      room:showCards(cards,player)
      if table.find(cards,function (id)
        return Fk:getCardById(id).color ~= Card.Black
      end) then
        for _, p in ipairs(room:getOtherPlayers(player)) do
          for t, c in pairs(tc) do
            if player.dead then break end
            local slash = Fk:cloneCard("slash")
            slash:addSubcards(c)
            slash.skillName = jiezhu.name
            if Fk:getCardById(c[1]).color == Card.Black and p.id == t.id and table.contains(cards,c[1]) and not p.dead and
            not p:isProhibited(player,slash) then
              room:useCard{
                from = p,
                tos = {player},
                card = slash,
                skill_name = jiezhu.name,
              }
            end
          end
        end
      else
        for _, id in ipairs(cards) do
          room:setCardMark(Fk:getCardById(id),"@@sj7__jiezhu",1)
        end
      end
    end,
})

jiezhu:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card, to)
    return card:getMark("@@sj7__jiezhu") > 0
  end,
})

return jiezhu